
* Reset frames
frame reset

* Open data and set background scheme
clear all
cd "INSERTPATH" 											// Remember to update file directory ("INSERTPATH")
use  "data_S1.dta", clear 

set scheme plotplain

* Rescales DVs to 0-1
gen support_inparty = . 
replace support_inparty = (feelings_dems/10) if pid < 0
replace support_inparty = (feelings_reps/10) if pid > 0
gen support_outparty = . 
replace support_outparty = (feelings_dems/10) if pid > 0
replace support_outparty = (feelings_reps/10) if pid < 0
gen aff_pol = (affective_polarization+10)/20

* Runs regressions, stores estimates and calls plot (Fig 1)
frame rename default data

* Vote-Switching
qui reg vote_outparty i.D if copartisan_D==1, rob
mat list r(table)
mat A1 = r(table)
qui reg vote_outparty i.D if copartisan_D==0, rob
mat list r(table)
mat A2 = r(table)

* In-Party Affect
qui reg support_inparty i.D if copartisan_D==1, rob
mat list r(table)
mat B1 = r(table)
qui reg support_inparty i.D if copartisan_D==0, rob
mat list r(table)
mat B2 = r(table)

* Out-Party Affect
qui reg support_outparty i.D if copartisan_D==1, rob
mat list r(table)
mat C1 = r(table)
qui reg support_outparty i.D if copartisan_D==0, rob
mat list r(table)
mat C2 = r(table)

* Affective polarization
qui reg aff_pol i.D if copartisan_D==1, rob
mat list r(table)
mat D1 = r(table)
qui reg aff_pol i.D if copartisan_D==0, rob
mat list r(table)
mat D2 = r(table)


mat H = 0,.85,A1[1,2],A1[5,2],A1[6,2]\ ///
		1,.8,B1[1,2],B1[5,2],B1[6,2]\ ///
		2,.75,C1[1,2],C1[5,2],C1[6,2]\ ///
		3,.7,D1[1,2],D1[5,2],D1[6,2]		
	
mat list H	


* make Panel A: 
frame create plot1
cwf plot1		
svmat H
rename H1 outcome
rename H2 Ypos
rename H3 b
rename H4 ll
rename H5 ul	

tw ///
	(rspike ll ul Ypos, horizontal lcolor(black)) ///
	(scatter Ypos b, msym(O) mc(black) msize(med) mlabel(b) mlabformat(%5.2fc) mlabposition(12)) ///
	, yscale(range(.69 .86) lc(none)) ytit("") ///
	ylab(.85 "Out-Party Voting" .8 "In-Party Affect" .75 "Out-Party Affect" .7 "Affective Polarization", notick glpattern(solid) glcolor(gs14%50)) ///
	xtit("Treatment Effect Estimate", size(small)) xscale(range(-.5 .25) lc(none)) xlab(-.4 -.2 0 .2, notick glpattern(solid) glcolor(gs14%50)) xline(0) ///
	legend(off) plotregion(lcolor(black) lwidth(medium)) ///
	title("{bf:A} In-Party Cheating", size(small) justification(left) pos(11)) ///
	name(S1_affect_A, replace)
	
	
* Panel B: out-party cheating	
mat I = 0,.85,A2[1,2],A2[5,2],A2[6,2]\ ///
		1,.8,B2[1,2],B2[5,2],B2[6,2]\ ///
		2,.75,C2[1,2],C2[5,2],C2[6,2]\ ///
		3,.7,D2[1,2],D2[5,2],D2[6,2]
					
mat list I		
	
* make plot 1B: 
frame create plot2
cwf plot2		
svmat I
rename I1 outcome
rename I2 Ypos
rename I3 b
rename I4 ll
rename I5 ul	

tw ///
	(rspike ll ul Ypos, horizontal lcolor(black)) ///
	(scatter Ypos b, msym(O) mc(black) msize(med) mlabel(b) mlabformat(%5.2fc) mlabposition(12)) ///
	, yscale(range(.69 .86) lc(none)) ytit("") ///
	ylab(none, notick) yline(.85, lpattern(solid) lcolor(gs14%50)) yline(.8, lpattern(solid) lcolor(gs14%50)) yline(.75, lpattern(solid) lcolor(gs14%50)) yline(.7, lpattern(solid) lcolor(gs14%50)) ///
	xtit("Treatment Effect Estimate", size(small)) xscale(range(-.5 .25) lc(none)) xlab(-.4 -.2 0 .2, notick glpattern(solid) glcolor(gs14%50)) xline(0) ///
	legend(off) plotregion(lcolor(black) lwidth(medium)) ///
	title("{bf:B} Out-Party Cheating", size(small) justification(left) pos(11)) ///
	aspect(.55,place(w)) ///
	name(S1_affect_B, replace)
	

graph combine S1_affect_A S1_affect_B, rows(1) ycommon 
graph display, xsize(8) ysize(2.5) scale(2.5)

graph export "S1_Fig1.pdf", as(pdf) replace	
	
	
	


